//
//  DialPersonInforViewController.m
//  ChengXinBao
//
//  Created by RongZhou on 17/2/15.
//  Copyright © 2017年 RongZhou. All rights reserved.
//

#import "DialPersonInforViewController.h"
#import <Masonry.h>
#import "CallModel.h"
#import "LLKCollectionManage.h"
#import "PPGetAddressBook.h"
#import <AFNetworking.h>
@interface DialPersonInforViewController ()
@property(nonatomic,copy)NSString *addressName;
@end

@implementation DialPersonInforViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createUIAboutPersonDetailInformation];
    NSLog(@"%@",self.phoneStr);
    NSLog(@"%@",self.userStr);
    // Do any additional setup after loading the view.
}
-(void)createUIAboutPersonDetailInformation{
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
    [self.view addSubview:view1];
    UILabel *label1 = [[UILabel alloc] init];
    [view1 addSubview:label1];
    label1.text = @"电话";
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(15);
        make.left.equalTo(view1.mas_left).offset(10);
        make.top.equalTo(view1.mas_top).offset(10);
    }];
    UILabel *label2 = [[UILabel alloc] init];
    [view1 addSubview:label2];
    label2.text = self.phoneStr;
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(15);
        make.left.equalTo(view1.mas_left).offset(10);
        make.top.equalTo(label1.mas_bottom).offset(10);
    }];
    UIButton *messageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [messageBtn setBackgroundImage:[UIImage imageNamed:@"Message"] forState:UIControlStateNormal];
    [messageBtn addTarget:self action:@selector(sendMessage:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:messageBtn];
    [messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(view1.mas_right).offset(-10);
        make.width.mas_equalTo(32);
        make.height.mas_equalTo(32);
        make.centerY.equalTo(view1.mas_centerY);
    }];
    UIButton *dialBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [dialBtn setBackgroundImage:[UIImage imageNamed:@"dialrecored"] forState:UIControlStateNormal];
    [dialBtn addTarget:self action:@selector(dialPhone:) forControlEvents:UIControlEventTouchUpInside];
    [view1 addSubview:dialBtn];
    [dialBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(messageBtn.mas_left).offset(-10);
        make.width.mas_equalTo(32);
        make.height.mas_equalTo(32);
        make.centerY.equalTo(view1.mas_centerY);
    }];
    if ([self.phoneStr isEqual:self.addressName]) {
        
    }else{
        UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 50, ScreenWidth, 40)];
        [self.view addSubview:view2];
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, ScreenWidth, 40)];
        [view2 addSubview:label];
        label.text = @"分享此电话号码";
        label.textColor = [UIColor greenColor];
        label.userInteractionEnabled = YES;
        label.font = [UIFont systemFontOfSize:20];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sharedPersonInfor)];
        [label addGestureRecognizer:tap];
    }
}
-(void)sharedPersonInfor{
    NSLog(@"00=%@",self.addressName);
    NSLog(@"11=%@",self.phoneStr);
    NSArray *array = @[self.userStr,self.phoneStr];
    NSLog(@"arra=%@",array);
    UIActivityViewController *activityView =[[UIActivityViewController alloc] initWithActivityItems:array applicationActivities:nil];
    //需要忽略的分享
    activityView.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypePostToWeibo,
        UIActivityTypeMessage,UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList,UIActivityTypePostToFlickr,];
    activityView.restorationIdentifier = @"activity";
    [activityView setTitle:@"分享"];
    [self presentViewController:activityView animated:TRUE completion:nil];
}

/**
 *  发送短信
 *
 *  @param btn <#btn description#>
 */
-(void)sendMessage:(UIButton *)btn{
    NSString *MessageStr = [NSString stringWithFormat:@"%@%@",@"sms://",self.phoneStr];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:MessageStr]];
}
/**
 *  拨打电话
 *
 *  @param btn <#btn description#>
 */
-(void)dialPhone:(UIButton *)btn{
    NSString *MessageStr = [NSString stringWithFormat:@"%@%@",@"tel://",self.phoneStr];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:MessageStr]];
    CallModel *model = [[CallModel alloc] initWithUserName:self.userStr AndUserPhonenumber:self.phoneStr AndUserCallTime:[self calueLocalDialPhoneNumberTime] AndUserAddress:self.phoneNumberArea];
    NSLog(@"%@",model.userAddress);
    [[LLKCollectionManage shareManager] addCollect:model];

}

/**
 *  获取当前的拨号时间
 *
 *  @return <#return value description#>
 */
-(NSString *)calueLocalDialPhoneNumberTime{
    NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
    NSDate *date = [NSDate date];
    NSDateFormatter * df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"YYYY年-MM月-dd日 HH:mm";
    [df setTimeZone:sourceTimeZone];//直接指定时区，北京时间
    return [df stringFromDate:date];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
